﻿
// MFCPCLTryDlg.cpp: 实现文件
//

//#include "pch.h"
#include "framework.h"
#include "MFCPCLTry.h"
#include "MFCPCLTryDlg.h"
#include "afxdialogex.h"
#include "pcd_read.h"
#include "CloudViewerRead.h"
#include "pcd_write.h"
#include "concatenate_clouds.h"
#include "PCDConverter.h"
#include "Kdtree_search.h"
#include "Octree_search.h"
#include "Octree_change_detection.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

using std::string;

// 用于应用程序“关于”菜单项的 CAboutDlg 对话框

class CAboutDlg : public CDialogEx
{
public:
	CAboutDlg();

// 对话框数据
#ifdef AFX_DESIGN_TIME
	enum { IDD = IDD_ABOUTBOX };
#endif

	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV 支持

// 实现
protected:
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialogEx(IDD_ABOUTBOX)
{
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx)
END_MESSAGE_MAP()


// CMFCPCLTryDlg 对话框



CMFCPCLTryDlg::CMFCPCLTryDlg(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_MFCPCLTRY_DIALOG, pParent)
	, M_edit1(_T(""))
{
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CMFCPCLTryDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Text(pDX, IDC_EDIT1, M_edit1);
	DDX_Control(pDX, IDC_EDIT1, m_editFile1);
	DDX_Control(pDX, IDC_EDIT2, m_editFile2);
	DDX_Control(pDX, IDC_EDIT3, savePath);
}

BEGIN_MESSAGE_MAP(CMFCPCLTryDlg, CDialogEx)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON1, &CMFCPCLTryDlg::OnBnClickedButton1)
	ON_BN_CLICKED(IDC_BUTTON2, &CMFCPCLTryDlg::OnBnClickedButton2)
	ON_BN_CLICKED(IDC_BUTTON3, &CMFCPCLTryDlg::OnBnClickedButton3)
	ON_BN_CLICKED(IDC_BUTTON4, &CMFCPCLTryDlg::OnBnClickedButton4)
	ON_BN_CLICKED(IDC_BUTTON5, &CMFCPCLTryDlg::OnBnClickedButton5)
	ON_BN_CLICKED(IDC_BUTTON7, &CMFCPCLTryDlg::OnBnClickedButton7)
	ON_BN_CLICKED(IDC_BUTTON8, &CMFCPCLTryDlg::OnBnClickedButton8)
	ON_BN_CLICKED(IDC_BUTTON6, &CMFCPCLTryDlg::OnBnClickedButton6)
	ON_BN_CLICKED(IDC_BUTTON9, &CMFCPCLTryDlg::OnBnClickedButton9)
	ON_BN_CLICKED(IDC_BUTTON10, &CMFCPCLTryDlg::OnBnClickedButton10)
	ON_BN_CLICKED(IDC_BUTTON11, &CMFCPCLTryDlg::OnBnClickedButton11)
	ON_BN_CLICKED(IDC_BUTTON12, &CMFCPCLTryDlg::OnBnClickedButton12)
	ON_BN_CLICKED(IDC_BUTTON13, &CMFCPCLTryDlg::OnBnClickedButton13)
	ON_BN_CLICKED(IDC_BUTTON14, &CMFCPCLTryDlg::OnBnClickedButton14)
	ON_BN_CLICKED(IDC_BUTTON15, &CMFCPCLTryDlg::OnBnClickedButton15)
	ON_BN_CLICKED(IDC_BUTTON16, &CMFCPCLTryDlg::OnBnClickedButton16)
	ON_BN_CLICKED(IDC_BUTTON17, &CMFCPCLTryDlg::OnBnClickedButton17)
END_MESSAGE_MAP()


// CMFCPCLTryDlg 消息处理程序

BOOL CMFCPCLTryDlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	// 将“关于...”菜单项添加到系统菜单中。

	// IDM_ABOUTBOX 必须在系统命令范围内。
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != nullptr)
	{
		BOOL bNameValid;
		CString strAboutMenu;
		bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
		ASSERT(bNameValid);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// 设置此对话框的图标。  当应用程序主窗口不是对话框时，框架将自动
	//  执行此操作
	SetIcon(m_hIcon, TRUE);			// 设置大图标
	SetIcon(m_hIcon, FALSE);		// 设置小图标

	// TODO: 在此添加额外的初始化代码

	return TRUE;  // 除非将焦点设置到控件，否则返回 TRUE
}

void CMFCPCLTryDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialogEx::OnSysCommand(nID, lParam);
	}
}

// 如果向对话框添加最小化按钮，则需要下面的代码
//  来绘制该图标。  对于使用文档/视图模型的 MFC 应用程序，
//  这将由框架自动完成。

void CMFCPCLTryDlg::OnPaint()
{
	if (IsIconic())
	{
		CPaintDC dc(this); // 用于绘制的设备上下文

		SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);

		// 使图标在工作区矩形中居中
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// 绘制图标
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialogEx::OnPaint();
	}
}

//当用户拖动最小化窗口时系统调用此函数取得光标
//显示。
HCURSOR CMFCPCLTryDlg::OnQueryDragIcon()
{
	return static_cast<HCURSOR>(m_hIcon);
}



void CMFCPCLTryDlg::OnBnClickedButton1()
{
	// TODO: 在此添加控件通知处理程序代码
	pcd_read pcdread;
	pcdread.Read();
}

//使用ColudView读点云文件
void CMFCPCLTryDlg::OnBnClickedButton2()
{
	// TODO: 在此添加控件通知处理程序代码
	CFileDialog    dlgFile(TRUE, NULL, NULL, OFN_HIDEREADONLY, _T("Describe Files (*.pcd)|*.pcd|All Files (*.*)|*.*||"), NULL);
	if (dlgFile.DoModal())
	{
		CString strFile = dlgFile.GetPathName();
		//Cstring 转string
		CString theCStr;
		std::string STDStr(CW2A(strFile.GetString()));
		
		CloudViewerRead cloudViewerRead;
		cloudViewerRead.LoadFile(STDStr);
	}
	
}

//写点云文件
void CMFCPCLTryDlg::OnBnClickedButton3()
{
	// TODO: 在此添加控件通知处理程序代码
	CFileDialog dlg(FALSE, NULL, NULL, OFN_HIDEREADONLY, _T("Describe Files (*.pcd)|*.pcd|All Files (*.*)|*.*||"), NULL);///TRUE为OPEN对话框，FALSE为SAVE AS对话框
	if (dlg.DoModal() == IDOK)
	{
		CString strFile = dlg.GetPathName();
		//Cstring 转string
		CString theCStr;
		std::string STDStr(CW2A(strFile.GetString()));
		STDStr += ".pcd";
		pcd_write pcdw;
		pcdw.Write(STDStr);
	}
}

//选择点云文件一
void CMFCPCLTryDlg::OnBnClickedButton4()
{
	// TODO: 在此添加控件通知处理程序代码
	// TODO: 在此添加控件通知处理程序代码
	CFileDialog    dlgFile(TRUE, NULL, NULL, OFN_HIDEREADONLY, _T("Describe Files (*.pcd)|*.pcd|(*.las)|*.las|All Files (*.*)|*.*||"), NULL);
	if (dlgFile.DoModal())
	{
		CString strFile = dlgFile.GetPathName();
		m_editFile1.SetWindowText(strFile); //设置输入框的内容

	}
}


//选择点云文件二
void CMFCPCLTryDlg::OnBnClickedButton5()
{
	// TODO: 在此添加控件通知处理程序代码
	// TODO: 在此添加控件通知处理程序代码
	// TODO: 在此添加控件通知处理程序代码
	CFileDialog    dlgFile(TRUE, NULL, NULL, OFN_HIDEREADONLY, _T("Describe Files (*.pcd)|*.pcd|All Files (*.*)|*.*||"), NULL);
	if (dlgFile.DoModal())
	{
		CString strFile = dlgFile.GetPathName();
		m_editFile2.SetWindowText(strFile); //设置输入框的内容

	}
}

//保存点云文件
void CMFCPCLTryDlg::OnBnClickedButton8()
{
	// TODO: 在此添加控件通知处理程序代码
	CFileDialog dlg(FALSE, NULL, NULL, OFN_HIDEREADONLY, _T("Describe Files (*.pcd)|*.pcd|All Files (*.*)|*.*||"), NULL);///TRUE为OPEN对话框，FALSE为SAVE AS对话框
	if (dlg.DoModal() == IDOK)
	{
		CString strFile = dlg.GetPathName();
		//strFile += ".pcd";
		//Cstring 转string
		savePath.SetWindowText(strFile);
	}
}

//字段连接
void CMFCPCLTryDlg::OnBnClickedButton7()
{
	
	//得到路径
	CString coludPathA,coludPathB,coludPathC;
	m_editFile1.GetWindowText(coludPathA);
	m_editFile2.GetWindowText(coludPathB);
     savePath.GetWindowText(coludPathC);

	 string strPathA, strPathB, strPathC;
	 strPathA = CW2A(coludPathA.GetString());
	 strPathB= CW2A(coludPathB.GetString());
	 strPathC= CW2A(coludPathC.GetString());

	 //连接点云
	 concatenate_clouds concatenateclouds;
	concatenateclouds.ConcatFields(strPathA, strPathB, strPathC);
}

//连接点云
void CMFCPCLTryDlg::OnBnClickedButton6()
{
	// TODO: 在此添加控件通知处理程序代码
	//得到路径
	CString coludPathA, coludPathB, coludPathC;
	m_editFile1.GetWindowText(coludPathA);
	m_editFile2.GetWindowText(coludPathB);
	savePath.GetWindowText(coludPathC);

	string strPathA, strPathB, strPathC;
	strPathA = CW2A(coludPathA.GetString());
	strPathB = CW2A(coludPathB.GetString());
	strPathC = CW2A(coludPathC.GetString());

	//连接点云
	concatenate_clouds concatenateclouds;
	concatenateclouds.Concat(strPathA, strPathB, strPathC);
	int result = MessageBox(TEXT("成功"), TEXT("提示"));

}

//las转PCD
void CMFCPCLTryDlg::OnBnClickedButton9()
{
	// TODO: 在此添加控件通知处理程序代码
	CString coludPathA, coludPathB;
	m_editFile1.GetWindowText(coludPathA);
	savePath.GetWindowText(coludPathB);

	string strPathA, strPathB;
	strPathA = CW2A(coludPathA.GetString());
	strPathB = CW2A(coludPathB.GetString());

	PCDConverter pcdConverter;
	pcdConverter.LASToPCD(strPathA, strPathB);
	int result = MessageBox(TEXT("转换成功"), TEXT("提示"));

}

//ply转PCD
void CMFCPCLTryDlg::OnBnClickedButton10()
{
	// TODO: 在此添加控件通知处理程序代码

	CString coludPathA, coludPathB;
	m_editFile1.GetWindowText(coludPathA);
	savePath.GetWindowText(coludPathB);

	string strPathA, strPathB;
	strPathA = CW2A(coludPathA.GetString());
	strPathB = CW2A(coludPathB.GetString());

	PCDConverter pcdConverter;
	pcdConverter.PlyToPCD(strPathA, strPathB);
	int result = MessageBox(TEXT("转换成功"), TEXT("提示"));
}


void CMFCPCLTryDlg::OnBnClickedButton11()
{
	// TODO: 在此添加控件通知处理程序代码 
	int result = MessageBox(TEXT("第三章\7\source  这个案例更加适合在Linux上面跑更快"), TEXT("提示"));
}


void CMFCPCLTryDlg::OnBnClickedButton12()
{
	//在MFC里面打开控制台
	AllocConsole();
	freopen("CONOUT$", "w+t", stdout);
	//freopen("CONIN$", "r+t", stdin);
	// 领域搜索代码
	Kdtree_search *kdtree_search = new Kdtree_search();
	kdtree_search->Test();
}


void CMFCPCLTryDlg::OnBnClickedButton13()
{
	// TODO: 在此添加控件通知处理程序代码
	AllocConsole();
	freopen("CONOUT$", "w+t", stdout);
	freopen("CONIN$", "r+t", stdin);
	std::cout << "Input:" << std::endl;
	int iTest = 0;
	std::cin >> iTest;
	fclose(stdout);
	fclose(stdin);
	FreeConsole();
}

//点云压缩
void CMFCPCLTryDlg::OnBnClickedButton14()
{
	// TODO:第4章\2\source 在此添加控件通知处理程序代码
	int result = MessageBox(TEXT("  这个案例需要在Linux上面,并且需要点云摄像头如ASUS Xtion"), TEXT("提示"));
}

//八叉树近邻搜索
void CMFCPCLTryDlg::OnBnClickedButton15()
{
	// TODO: 在此添加控件通知处理程序代码
	AllocConsole();
	freopen("CONOUT$", "w+t", stdout);
	//freopen("CONIN$", "r+t", stdin);
	// 领域搜索代码
	Octree_search *octree_search = new Octree_search();
	octree_search->Test();
}



//无序点云数据集空间变换检测
void CMFCPCLTryDlg::OnBnClickedButton16()
{
	// TODO: 在此添加控件通知处理程序代码
	AllocConsole();
	freopen("CONOUT$", "w+t", stdout);
	//freopen("CONIN$", "r+t", stdin);
	// 领域搜索代码
	Octree_change_detection *octree_change_detection = new Octree_change_detection();
	octree_change_detection->Test();
	
}


//可视化深度图像
void CMFCPCLTryDlg::OnBnClickedButton17()
{
	//打开深度图像

}
